using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
using Microsoft.SharePoint;

namespace Microsoft.SharePoint.Administration.UsageSettings
{
    class UsageLogSiteReceiver : SPFeatureReceiver
    {

        #region Private Fields
        private const string CUSTOM_TIMER_JOB_NAME = "Usage Log Processor Timer Job";

        #endregion

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            logMessage("starting activate", EventLogEntryType.Information);

            SPWeb web = properties.Feature.Parent as SPWeb;

            SPDocumentLibrary myLib = (SPDocumentLibrary)web.Lists["Shared Documents"];

            logMessage("site URL --" + web.Url, EventLogEntryType.Information);

            SPFolder myFolder = myLib.RootFolder;
            logMessage("folder URL --" + myFolder.Url, EventLogEntryType.Information);

            SPFile file = myFolder.Files.Add("usageLog2.xlsx", File.ReadAllBytes(@"C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\LOGS\Usage\usageLog2.xlsx"));
            logMessage("file URL --" + file.Url, EventLogEntryType.Information);

            web.AllowUnsafeUpdates = true;
            web.Update();

        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {

        }

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {

        }

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {

        }

        private static void logMessage(string message, EventLogEntryType type)
        {

            if (!EventLog.SourceExists("Custom SharePoint Features"))
                EventLog.CreateEventSource("Custom SharePoint Features", "Application");
            EventLog.WriteEntry("Custom SharePoint Features", message, type);

        }
    }
}
